home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-18 | 7.8 KB | 327 lines | [TEXT/ALFA] |
-
- if $startingUp {
- set ftpMenu "•141"
- addMenu ftpMenu
- return
- }
-
-
-
- proc ftpMenu {} {}
-
-
- if {![info exists savePostHooks] || ![string match {*ftpPostHook*} $savePostHooks]} {
- lappend savePostHooks ftpPostHook
- }
-
-
- proc ftpPostHook {name} {
- global fetched
- if {[info exists fetched($name)]} {
- message "Updating '[file tail $name]'…"
- set specs $fetched($name)
- if {[string length [cadr $specs]]} {
- ftpStore $name [car $specs] "[cadr $specs]/[file tail $name]" [caddr $specs] [cadddr $specs]
- } else {
- ftpStore $name [car $specs] "[file tail $name]" [caddr $specs] [cadddr $specs]
- }
- }
- }
-
-
- # createFileSet
- proc rebuildFtpMenu {} {
- global savedMounts ftpMenu
-
- menu -n $ftpMenu -p ftpMenuProc {
- help
- palette
- "(-"
- "<S/ibrowse…"
- "<S/i<IbrowseCurrent…"
- addMountPoint…
- removeMountPoint…
- flushCache
- "(-"
- "createFileset"
- setDefaults
- "(-"
- }
- if {[info exists savedMounts]} {
- foreach m [lsort -ignore [array names savedMounts]] {
- addMenuItem -m -l "b " $ftpMenu $m
- }
- }
- }
-
- rebuildFtpMenu
-
- insertMenu $ftpMenu
-
- proc ftpMenuProc {menu item} {
- global modifiedArrVars savedMounts PREFS fetched HOME ftpMenu
- switch $item {
- help {editMark "$HOME:Help:Manual" "Ftp Browser" -r}
- palette {float -m $ftpMenu -n FTP -M -1}
- browse {eval ftpBrowse [lrange [getLogin {Browse remote machine:} 0] 0 3]}
- browseCurrent { if {[info exists fetched([car [winNames -f]])]} {
- eval ftpBrowse $fetched([car [winNames -f]])
- } else {
- beep; message "'[car [winNames]]' not from remote host."
- }}
- addMountPoint { addMountPoint }
- createFileset { ftpCreateFileset }
- removeMountPoint {
- set pt [listpick -p "Remove which mount point?" [lsort -ignore [array names savedMounts]]]
- unset savedMounts($pt)
- removeArrDef savedMounts $pt
- rebuildFtpMenu
- }
- setDefaults {
- global ftpDefaults modifiedVars
- set ftpDefaults [lrange [getLogin "Enter defaults that you wish saved:" 0] 0 3]
- lappend modifiedVars ftpDefaults
- }
- flushCache { rm "$PREFS:ftptmp:*" }
- default {
- eval ftpBrowse $savedMounts($item)
- }
- }
- }
-
-
- proc ftpFilesetOpen {menu item} {
- global gfileSets PREFS fetched fileSetsExtra
-
- if {[set ind [lsearch $gfileSets($menu) "*$item"]] >= 0} {
- set f [lindex $gfileSets($menu) $ind]
- set lnm [file tail $f]
- regsub -all {:} $f {/} f
- set nm "$PREFS:ftptmp:$lnm"
- set specs $fileSetsExtra($menu)
- if {![file exists $nm]} {
- ftpFetch $nm [car $specs] $f [caddr $specs] [cadddr $specs]
- }
- edit $nm
- set fetched($nm) $specs
- }
- }
-
-
- proc ftpCreateFileset {} {
- global gfileSets gfileSetsType PREFS fileSetsExtra
-
- set specs [getLogin]
- set name [car $specs]
- set host [cadr $specs]
- set path [caddr $specs]
- set user [cadddr $specs]
- set password [caddddr $specs]
- set pattern "^[prompt {Name pattern?} {.*.[ch]}]$"
- set path [string trimright $path {/}]
-
- set fileSetsExtra($name) [list $host $path $user $password]
-
- if { ![file exists "$PREFS:ftptmp:"] } {
- mkdir "$PREFS:ftptmp:"
- }
- set nm "$PREFS:ftptmp:listing.$path"
- ftpList $nm $host $path $user $password
- set files {}
- foreach f [processListing $nm] {
- if {![string match {*/} $f] && [regexp $pattern $f]} {
- lappend files "$path/$f"
- }
- }
- regsub -all {/} $files {:} files
-
- global gfileSets gfileSetsType
- set gfileSets($name) [lsort -command sortByTail $files]
- set gfileSetsType($name) ftp
- if {[askyesno "Save project fileset?"] == "yes"} {
- addArrDef gfileSetsType $name ftp
- addArrDef gfileSets $name $gfileSets($name)
- addArrDef fileSetsExtra $name $fileSetsExtra($name)
- }
- return $name
- }
-
-
- proc getLogin {{prompt {All but 'password' are required:}} {nm 1}} {
- global ftpDefaults
- if {[info exists ftpDefaults]} {
- set defs $ftpDefaults
- } else {
- set defs {"" "" "" ""}
- }
- set left 10
- set right 100
- set top 10
- set bottom 30
- set eleft [expr $left + 100]
- set eright 370
- set incr 30
-
- set height 198
-
- if $nm {incr height $incr}
- set l "dialog -w 400 -h $height -t [list $prompt] $left $top 400 $bottom"
-
- if {$nm} {
- incr top $incr
- incr bottom $incr
- lappend l -t {Name:} $left $top $right $bottom
- lappend l -e {} $eleft $top $eright $bottom
- }
-
- incr top $incr
- incr bottom $incr
- lappend l -t {Host:} $left $top $right $bottom
- lappend l -e [car $defs] $eleft $top $eright $bottom
-
- incr top $incr
- incr bottom $incr
- lappend l -t {Path:} $left $top $right $bottom
- lappend l -e [cadr $defs] $eleft $top $eright $bottom
-
- incr top $incr
- incr bottom $incr
- lappend l -t {UserID:} $left $top $right $bottom
- lappend l -e [caddr $defs] $eleft $top $eright $bottom
-
- incr top $incr
- incr bottom $incr
- lappend l -t {Password:} $left $top $right $bottom
- lappend l -e [cadddr $defs] $eleft $top $eright $bottom
-
- incr top [expr $incr + 10]
- incr bottom [expr $incr + 10]
- lappend l -b "OK" $left $top $right [expr $top + 20]
- lappend l -b "Cancel" [expr $left + 200] $top [expr $right + 200] [expr $top + 20]
-
- set res [eval "$l"]
- if {[lindex $res end]} {error "Cancel"}
- return $res
- }
-
-
- proc addMountPoint {} {
- global savedMounts modifiedArrVars
-
- set res [getLogin]
- if {[lindex $res 5]} {
- set savedMounts([car $res]) [lrange $res 1 4]
- lappend modifiedArrVars savedMounts
- rebuildFtpMenu
- }
- }
-
-
- proc ftpFetch {localName host path user password} {
- global ftpSig
- watchCursor
- launchBackApplSigs [list Arch] ftpSig
- set fd [open $localName "w"]
- close $fd
- AEBuild -r -t 30000 'Arch' Arch Ftch FTPh "“$host”" FTPc "“$path”" ArGU "“$user”" ArGp "“$password”" ---- [makeAlis $localName]
- }
-
- proc ftpStore {localName host path user password} {
- watchCursor
- AEBuild -q -t 30000 'Arch' Arch Stor ---- [makeAlis $localName] FTPh "“$host”" FTPc "“$path”" ArGU "“$user”" ArGp "“$password”"
- }
-
- proc handleReply {rep} {
- global ALPHA lastReply
- message "Remote save finished."
- set lastReply $rep
- }
-
- # 'localName' must be a preexisting file, this is a makeAlis limitation
- proc ftpList {localName host path user password} {
- global ftpSig
- watchCursor
- launchBackApplSigs [list Arch] ftpSig
- set fd [open $localName "w"]
- close $fd
- AEBuild -r -t 30000 '$ftpSig' Arch List FTPh "“$host”" FTPc "“$path”" ArGU "“$user”" ArGp "“$password”" {----} [makeAlis $localName]
- }
-
-
- proc processListing {path} {
- set fd [open $path "r"]
- set lines [split [read $fd] "\n"]
- close $fd
- set files {}
- foreach f [cdr [lreplace $lines end end]] {
- set nm [lindex $f end]
- if {[string length $nm]} {
- if {[string match "d*" $f]} {
- lappend files "$nm/"
- } else {
- lappend files $nm
- }
- }
- }
- return $files
- }
-
-
- proc ftpBrowse {host dir user password} {
- global PREFS fetched lastFtpDir
-
- watchCursor
- if {![string length $password]} {
- set password [prompt "Password:" ""]
- }
-
- if {![file exists "$PREFS:ftptmp"]} {
- mkdir "$PREFS:ftptmp"
- }
- if {$dir == {-}} {
- if {![info exists lastFtpDir] || ![string length $lastFtpDir]} {set lastFtpDir ""}
- set dir [prompt "'$host' dir:" $lastFtpDir]
- }
- set dir [string trimright $dir {/}]
- set lastFtpDir $dir
-
- set num 0
- for {set i [expr [string length $dir] - 1]} {$i >= 0} {incr i -1} {
- scan $dir "%c" char
- incr num $char
- }
-
- set nm "$PREFS:ftptmp:listing.$num"
-
- if {![file exists $nm]} {
- ftpList $nm $host $dir $user $password
- }
- set files [concat {..} [processListing $nm]]
- set file [listpick -p "$dir/" $files]
- if {$file == {..}} {
- if {[regexp {((/|\w)+)/\w+} $dir dummy sub]} {
- return [ftpBrowse $host $sub $user $password]
- } else {
- return [ftpBrowse $host "" $user $password]
- }
- }
- if {[string match {*/} $file]} {
- if {[string length $dir]} {
- return [ftpBrowse $host [string trimright "$dir/$file" {/}] $user $password]
- } else {
- return [ftpBrowse $host [string trimright "$file" {/}] $user $password]
- }
- }
-
- set nm "$PREFS:ftptmp:$file"
- if {![file exists $nm]} {
- if {[string length $dir]} {
- ftpFetch $nm $host "$dir/$file" $user $password
- } else {
- ftpFetch $nm $host "$file" $user $password
- }
- }
- edit $nm
- set fetched($nm) [list $host $dir $user $password]
- }
-